package stephencarmody.random_rotating_triangles;

import stephencarmody.k8.core.Logic;
import stephencarmody.k8.core.SceneNode;
import stephencarmody.k8.text.Text;
import stephencarmody.k8.util.Camera;
import stephencarmody.k8.wt.Layer;

public final class HUD extends Logic {

	private SceneNode 	scenenode;
	private Camera 		camera;
	private Text 		position;
	private FPSCounter  fpsCounter;
	private Layer		layer;
	private float		depth;
	private float		textScale;
	
	/** Creates a new instance of HUD */
	public HUD() {
		camera = Camera.getInstance();
		
		// Set default depth at just a little further than near clipping plane
		depth = camera.getNearClip() + 0.1f;
		
		// Get screen limits
		layer = new Layer(depth);
		
		// Root SceneNode, translated -width/2, -height/2
		scenenode = new SceneNode();
		scenenode.moveRight(-layer.getWidth()/2); 
		scenenode.moveUp(-layer.getHeight()/2);
		camera.appendChild(scenenode);
		scenenode.moveForward(depth);
		
		// Set the text scaling proportional to width
		textScale = layer.getWidth()/2000;
		
		// Position
		position = new Text();
		position.setScale(textScale);
		position.moveRight(layer.getWidth()/2);
		position.moveUp(0.001f);
		scenenode.appendChild(position);
		
		// FPS Counter
		fpsCounter = new FPSCounter();
        Text text = fpsCounter.getText();
        text.setScale(textScale);
        text.moveRight(0.001f);
        text.moveUp(0.001f);
        scenenode.appendChild(text);
		
		setUpdateRate(10);
	}

	@Override
	public void update(long time) {
		position.setText(((float)(int)(camera.T[3]*100)/100) + ", " + ((float)(int)(camera.T[7]*100)/100) + ", " + ((float)(int)(camera.T[11]*100)/100));
	}
	
}
